"""
python类和对象
"""
import subprocess


# 设计一个类
def ring():
    import winsound
    # winsound.Beep(2000, 3000)


class Clock:
    id = None  # 编号
    price = None  # 价格

    def ring(self):
        # 播放音乐 20s
        try:
            # macOS 系统使用这个
            subprocess.call(["afplay", "/Users/dongjian/Documents/音视频/刀郎-罗刹海市.wav"], timeout=20)
            # windows 系统可以直接使用默认的 winsound.Beep
        except:
            print("播放时长时间到，退出播放")


# 创建类对象
clock1 = Clock()
clock2 = Clock()

# 设置属性
clock1.id = "003030"
clock1.price = 19.99
print(f"闹钟ID{clock1.id}, 闹钟价格{clock1.price}")
clock1.ring()

clock2.id = "003031"
clock2.price = 21.99
print(f"闹钟ID{clock2.id}, 闹钟价格{clock2.price}")
clock1.ring()
